﻿namespace FSpec.Runner.Model

open System
open System.Reflection 
open Gallio.Common.Reflection 
open Gallio.Model.Helpers 
open Gallio.Model
open System.Linq

[<AutoOpen>]
module ModelHelper =
   
    let insertXmlDocsInto (testInfo:Tree.Test) (codeElement:ICodeElementInfo) =
        let xmlDocs = codeElement.GetXmlDocumentation()
        if not (String.IsNullOrEmpty xmlDocs) then testInfo.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocs) 

    let getCategoriesFor (codeElement:ICodeElementInfo) =
        let declaringType = (ReflectionUtils.GetType codeElement)
        let categories = match declaringType with
                            | null -> [ "Specifications" ]
                            | _ -> 
                                let typeName = declaringType.Name
                                let nsName = (ReflectionUtils.GetNamespace codeElement)
                                                .Name
                                                .Split([|'.'|])
                                                .Last()
                                [ "Specifications"; nsName + "-" + typeName ]
        categories.ToList()